package com.array;

public class array04 {
    public static void main(String[] args) {
        int[] arrays = {1,2,3,4,5};
        //JDK1.5  没有下标  增强型的for循环
//        for (int array : arrays) {
//            System.out.println(array);
//        }
//        printArray(arrays);//调用
        int[] reverse = reverse(arrays);
        printArray(reverse);
    }
    //打印数组元素
    //static方便直接调用
    public static void printArray(int[] arrays){
        for (int i = 0; i < arrays.length; i++) {
            System.out.print(arrays[i]+"  ");
        }
    }
    //反转数组
    //reverse 反转
    public static int[] reverse(int[] arrays){
        int[] result = new int[arrays.length];

        //反转的操作
        for (int i = 0,j=result.length-1; i < result.length; i++,j--) {
//            result[] = arrays[i];
            result[i]= arrays[j];
        }

        return result;
    }
}
